<?php
include_once '../meihe/common.php';
if ($islogin == 1) {
} else exit("<script language='javascript'>window.location.href='./login.php';</script>");
?>
<?php
if (isset($_GET['kw'])) {
	$sql = " sbm='{$_GET['kw']}'";
	$numrows = $DB->count("SELECT count(*) from meihe_api WHERE{$sql}");
	$con = '包含 ' . $_GET['kw'] . ' 的共有 <b>' . $numrows . '</b> 个短链';
	$link = '&kw=' . $_GET['kw'];
} else {
	$numrows = $DB->count("SELECT count(*) from meihe_api WHERE 1");
	$sql = " 1";
	$con = '平台共有 <b>' . $numrows . '</b> 个短链';
}
?>
<form name="form1" id="form1">
	<div style="white-space:nowrap;overflow-x: auto;">
		<table class="layui-table layuiadmin-page-table">
			<thead>
				<tr>
					<th>
						<div class="custom-control custom-checkbox"><input name="chkAll1" type="checkbox" id="chkAll1" onclick="selectAll(this);" value="checkbox" class="custom-control-input"><label class="custom-control-label" for="chkAll1"></label></div>ID
					</th>
					<th>识别码</th>
					<th>调用服务</th>
					<th>已被执行</th>
					<th>显示名称</th>
					<th>返回类型</th>
					<th>归属用户</th>
					<th>接口类型</th>
					<th>是否提示</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody>
				<?php
				$pagesize = isset($_GET['num']) ? intval($_GET['num']) : 30;
				$pages = ceil($numrows / $pagesize);
				$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
				$offset = $pagesize * ($page - 1);
				$rs = $DB->query("SELECT * FROM meihe_api WHERE{$sql} order by idd limit $offset,$pagesize");
				while ($res = $DB->fetch($rs)) {
					$bsc = $DB->count("SELECT count(*) from meihe_report WHERE 1 and duanl='{$res['sbm']}'");
					if ($res['dljk'] == 3) {
						$dljk = "<span style='color:#008000;'>自定义接口</span>";
					} elseif ($res['dljk'] == 4) {
						$dljk = "<span style='color:#008000;'>同系统接口</span>";
					} elseif ($res['dljk'] == 5) {
						$dljk = "<span style='color:#008000;'>本地接口</span>";
					}
					if ($res['jkfl'] == 1) {
						$jkfl = "<span style='color:#DC143C;'>通用接口</span>";
					} elseif ($res['jkfl'] == 2) {
						$jkfl = "<span style='color:#008000;'>权会员使用</span>";
					}
					if ($res['format'] == 1) {
						$fhlx = "<span style='color:#FF8C00;'>TXT返回</span>";
					} elseif ($res['format'] == 2) {
						$fhlx = "<span style='color:#DC143C;'>JSON返回</span>";
					}
					$content = explode('*', $res['content'] ?? '');
					$content = mb_substr($content[0], 0, 16, 'utf-8');
					echo '<tr><td><div class="custom-control custom-checkbox"><input type="checkbox" name="checkbox[]" id="workorder' . $res['id'] . '" value="' . $res['id'] . '" class="custom-control-input"><label class="custom-control-label" for="workorder' . $res['id'] . '"></label></div>' . $res['id'] . '</td><td>' . $res['sbm'] . '</td><td>' . $jkfl . '</td><td>' . $bsc . ' 次</td><td>' . $res['name'] . '</td><td>' . $fhlx . '</td><td>' . ($res['upzid'] ? '<font color="#FF5722" size="3">' . $userrow['user'] . '</font>' : '<font color="#01AAED" size="3">平台站长</font>') . '</td><td>' . $dljk . '</td><td><input type="checkbox" id="switch' . $res['id'] . '" onclick="Active(' . $res['id'] . ')"' . ($res['jktz'] == 1 ? ' checked ' : ' ') . 'data-switch="success"/><label for="switch' . $res['id'] . '" data-on-label="是" data-off-label="否" class="mb-0 d-block"></label></td><td><a class="btn btn-xs sort_btn" title="移到上一行" onclick="sort(' . $res['id'] . ',0)">置顶</a><a class="btn btn-xs sort_btn" title="移到上一行" onclick="sort(' . $res['id'] . ',1)"><i class="layui-icon layui-icon-up"></i></a><a class="btn btn-xs sort_btn" title="移到下一行" onclick="sort(' . $res['id'] . ',2)"><i class="layui-icon layui-icon-down"></i></a><a class="btn btn-xs sort_btn" title="移到上一行" onclick="sort(' . $res['id'] . ',3)">底部</a><a href="duanl.php?mod=edit&id=' . $res['id'] . '" class="btn btn-info btn-xs">编辑</a>&nbsp;<a class="btn btn-xs btn-danger" onclick="sitedel(' . $res['id'] . ')">删除</a></td></tr>';
				}
				?>
			</tbody>
		</table>
		<div class="form-group mb-3">
			<input type="hidden" name="content" />
			<label for="example-input-normal" style="font-weight: 500">操作：
				<select class="form-control" style="display: inline;width: auto;" name="aid">
					<option selected>批量操作</option>
					<option value="1">&gt;改为通用</option>
					<option value="2">&gt;改为会员</option>
					<option value="4">&gt;删除选中</option>
				</select>
				<button class="btn btn-sm btn-primary" type="button" onclick="change()">确定</button>
			</label>
		</div>
	</div>
</form>
<div class="text-center">
	<?php
	#分页
	$pageList = new Page($numrows, $pagesize, 1, $link ?? '');
	echo $pageList->showPage();
	?>
</div>
<script>
	$("#blocktitle").html('<?php echo $con ?>');
</script>